import java.math.BigInteger;


public class If implements Node{
	public String token = "<if>";
	public Node cond;
	public Node stmt_seq;
	public Node stmt_seq2 = null;
			
	public If(){
		
		cond = new Cond();
		int token = PSTree.Core_TK.getToken();
		if(token != 6){
			System.out.println("Error: expecting \"then\"");
			System.exit(1);
		}
		// skip then
		PSTree.Core_TK.skipToken();
		// parse statement sequence
		this.stmt_seq = new Stmt_Seq();
		//-------------------------------------------------------------------------
		//check for else
		//-------------------------------------------------------------------------
		token = PSTree.Core_TK.getToken();
		if(token == 7){
			//skip else
			PSTree.Core_TK.skipToken();
			//parse else statement
			this.stmt_seq2 = new Stmt_Seq();
			
		}
		// expecting end token
		token = PSTree.Core_TK.getToken();
		if(token != 3){
			System.out.println("Error: expecting \"end\"");
			System.exit(1);
		}
		// skip end token
		PSTree.Core_TK.skipToken();
		
		
	}

	@Override
	public void print(int indent) {
		System.out.print("if");
		this.cond.print(indent);
		System.out.print("\n");
		PSTree.print_ind(indent);
		System.out.print("then\n");
		this.stmt_seq.print(indent+1);
		
		if(this.stmt_seq2 != null){
			PSTree.print_ind(indent);
			System.out.print("else\n");
			this.stmt_seq2.print(indent+1);
			
		}
		PSTree.print_ind(indent-1);
		System.out.println("end;");
	}

	
	public void execute() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public BigInteger intexecute() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean compexecute() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public String Stringexcec() {
		// TODO Auto-generated method stub
		return null;
	}
}
